use crate::{connection::Connection, db::Db, frame::Frame, Result};

#[derive(Debug)]
pub struct Unknown {
    command_name: String,
}

impl Unknown {
    pub fn new(command_name: String) -> Self {
        Self { command_name }
    }

    pub fn command_name(&self) -> &str {
        &self.command_name
    }

    pub async fn apply(self, dst: &mut Connection) -> Result<()> {
        let response = &Frame::Error(format!("ERR unknown command '{}'", self.command_name));

        debug!("{:?}", response);

        dst.write_frame(response).await?;

        Ok(())
    }
}
